package com.togo.algorithm.medium.dp;

/**
 * @Author taiyn
 * @Description TODO
 * @Date 下午11:11 2022/4/18
 **/
public class Offer13 {

    public int movingCount(int m, int n, int k) {

        int result = 0;
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                if(check(i, j, k)) result++;
            }
        }

        return result;
    }

    private boolean check(int i, int j, int k) {

        String si = String.valueOf(i);
        String sj = String.valueOf(j);
        for(char c : si.toCharArray()) {
            int t = c - '0';
            k -= t;
            if(k < 0) {
                return false;
            }
        }

        for(char c : sj.toCharArray()) {
            int t = c - '0';
            k -= t;
            if(k < 0) {
                return false;
            }
        }

        return true;
    }

    public static void main(String[] args) {

        Offer13 offer13 = new Offer13();
        offer13.movingCount(16, 8, 4);
    }
}
